<template>
    <div class="pay-list">
        <div v-if="goodsList.length>0">
            <van-row>
                <van-col span="24" v-for="item in goodsList" :key="item.id">
                    <van-card
                        :num="item.count"
                        :price="item.price"
                        :desc="item.goods_desc"
                        :title="item.goods_name"
                        currency="¥"
                        :thumb="fixUrl(item.goods_img)">
                        <template #footer>
                            <div v-if="item.is_delivery">
                                <van-button size="small" type="primary">已发货</van-button>
                            </div>
                            <div v-else>
                                <van-button @click="delivery(item)" size="small" type="primary">发货
                                </van-button>
                            </div>
                        </template>
                    </van-card>
                </van-col>
            </van-row>
        </div>
        <div v-else>
            <van-empty description="暂无数据"></van-empty>
        </div>
    </div>
</template>

<script>
import {delivery, getOrderList} from "@/api/order";
import {Dialog} from "vant";
import {getDeliveryList} from "../../api/order";

export default {
    name: "SellerOrders",
    data() {
        return {goodsList: []}
    },
    created() {
        this.getOrderList();
    },
    watch: {},
    computed: {
        APIDomainName() {
            return process.env.VUE_APP_APIDOMAINNAME;
        },
    },
    methods: {
        async getOrderList() {
            try {
                let result = await getDeliveryList();
                this.utils.resultList(result, "订单为空")
                this.goodsList = result.data
            } catch (error) {
                await Dialog.alert({title: "错误", message: error});
            }
        },
        fixUrl(img) {
            return this.utils.fixUrl(img)
        },
        async delivery(item) {
            item.is_delivery = 1
            let result = await delivery({id: item.id})
            this.utils.resultEnd(result,"发货")
            // this.$toast("发货中。。。")
        }
    }
}
</script>

<style lang="less" scoped>
.card-item {
    margin-top: 5px;
    margin-right: 5px;
    margin-left: 5px;
    margin-bottom: 0px;
    background-color: rgb(243, 239, 239);
    font-size: 16px;
}

.card-header {
    padding: 5px 5px;
    color: #999;
    font-size: 16px;
    display: flex;
    justify-content: space-between;

    span.title {
        color: #888;
    }

    span.status {
        font-weight: bold;
    }
}

.amount {
    padding: 5px 5px;
    text-align: right;
    color: #6b6969;
    font-weight: bold;
    background-color: rgb(216, 219, 217);
}
</style>
